package stats

import (
	"encoding/json"

	"code.byted.org/gopkg/env"
)

// To use this pkg, following flags should be passed to go build:
// GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/pkg/stats.Name=${NAME}"
// GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/pkg/stats.Version=${VERSION}"
// GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/pkg/stats.BuildTime=${BUILDTIME}"
// GO_LDFLAGS="$GO_LDFLAGS -X ${REPO}/pkg/stats.GitSHA1=${GitSHA1}"

var (
	// Name is App name
	Name = "Not Provide"
	// Version is App version
	Version = "Not Provide"
	// BuildTime is App binary build time: `date +"%Y%m%d%H%M%S"`
	BuildTime = "Not Provide"
	// GitSHA1 is App sha1: `git rev-parse --short HEAD`
	GitSHA1 = "Not Provide"
)

// GetVersion gets version in json marshaled format
func GetVersion() []byte {
	v := map[string]string{
		"Name":      Name,
		"Version":   Version,
		"BuildTime": BuildTime,
		"GitSHA1":   GitSHA1,
		"DC":        env.IDC(),
		"Cluster":   env.Cluster(),
	}
	d, _ := json.MarshalIndent(v, "", "    ")
	return d
}
